﻿using Kairos.Models;
using System.Web.Mvc;
using System.Linq;
using System;
using System.Web;

namespace Kairos.Controllers
{
    public class HomeController : Controller
    {
        private myContext db = new myContext();

        [AccessControl(Roles.All)]
        public ActionResult Index()
        {
            return RedirectToAction("Document", "Search", null);
        }

        //
        // GET: /Home/AlarmeJson

        [AccessControl(Roles.All)]
        public ActionResult AlarmeJson()
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            int expiredDocuments = db.Documents.Count(d => DateTime.Compare(DateTime.Today, d.DateExpiration) >= 0);
            int expiredGraphes = db.Graphes.Count(d => DateTime.Compare(DateTime.Today, d.DateExpiration) >= 0);
            int unreferencedVtoms = db.Vtoms.Count(d => d.DocID == null);

            return Json(
                new
                {
                    expiredDocuments = expiredDocuments,
                    expiredGraphes = expiredGraphes,
                    unreferencedVtoms = unreferencedVtoms
                },
                JsonRequestBehavior.AllowGet);
        }
    }
}
